﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MINERP.BLL.PrintManage;
using MINERP.MODEL.FoundationModel;

namespace MINERP.Frontier
{
    public partial class FrmCalibrationPaperLength : Form
    {
        public delegate void RefreshUsingPaperHander(int printerid);
        public delegate void RefreshStatusHander();

        public RefreshUsingPaperHander refreshUsingPaperHander;
        public RefreshStatusHander refreshStatusHander;
        private PaperBLL paperBLL = new PaperBLL();

        private Printer_Info _printer = null;

        public Printer_Info Printer
        {
            get { return _printer; }
            set { _printer = value; }
        }

        public FrmCalibrationPaperLength()
        {
            InitializeComponent();
        }

        private void FrmCalibrationPaperLength_Load(object sender, EventArgs e)
        {

        }

        private void btnAddLength_Click(object sender, EventArgs e)
        {
            if (DataCheck())
            {
                int ret = paperBLL.CalibrationPaperLength(_printer, Convert.ToDouble(txtCalibrationLength.Text)/100, true);
                if (ret == 0)
                {
                    refreshUsingPaperHander.Invoke(_printer.PrinterID);
                    refreshStatusHander.Invoke();
                    MessageBox.Show("校正打印纸长度成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("请检查数据库连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
           
        }

        private void btnSubLength_Click(object sender, EventArgs e)
        {
            if (DataCheck())
            {
                int ret = paperBLL.CalibrationPaperLength(_printer, Convert.ToDouble(txtCalibrationLength.Text)/100, false);
                if (ret == 0)
                {
                    refreshUsingPaperHander.Invoke(_printer.PrinterID);
                    refreshStatusHander.Invoke();
                    MessageBox.Show("校正打印纸长度成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }

                else if (ret == -2)
                {

                    MessageBox.Show("打印纸剩余长度小于校正长度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("请检查数据库连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
 
            }

        }

        private bool DataCheck()
        {

            if (string.IsNullOrEmpty(txtCalibrationLength.Text.Trim()))
            {
                txtCalibrationLength.Focus();
                MessageBox.Show("请输入校正长度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
